import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-11-12
 * Time:16:32
 */
public class QuickSort {
    public static void main(String[] args) {
        int[] arr = {9,4,1,2,0,6,5,3,10,7,8};
        quickSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }

    private static void quickSort(int[] arr, int left, int right) {
        if(left > right) {
            return;
        }
        int base = arr[left];
        int i = left;
        int j = right;
        while (i < j) {
            //让对面先走
           while (i < j && arr[j] >= base) {
                j--;
            }
            while (i < j && arr[i] <= base) {
                i++;
            }

            if(i< j) {
                int tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
            }
        }
        arr[left] = arr[i];
        arr[i] = base;
        quickSort(arr,left,i-1);
        quickSort(arr,i+1,right);
    }
}
